import { FC, Suspense, lazy } from 'react';
import { createBrowserRouter, RouteObject } from 'react-router-dom'
const fullModules = import.meta.glob<false, string, { default: FC }>('../views/**/*.tsx')
const r = /\.\.\/views(.*)\.tsx/
const routes = Object.entries(fullModules).map<RouteObject>(([k, ComponentFunction]) => {
    const Component = lazy(ComponentFunction)
    const path = k.replace(r, '$1')
    return {
        path,
        element: <Suspense fallback={<div>加载中</div>}><Component /></Suspense>
    }
})
export const router = createBrowserRouter(routes);